<%--
  Created by IntelliJ IDEA.
  User: Administrator
  Date: 2021/10/25
  Time: 9:34
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ page import="java.sql.*" %>
<%@ page import="java.util.*" %>
<html>
<head>
    <title>Title</title>
</head>
<body>
<%
    String a = request.getParameter("name");
    String b = request.getParameter("sex");

    String driverName = "com.mysql.cj.jdbc.Driver";
    String url = "jdbc:mysql://localhost:3306/mall?useUnicode=true&characterEncoding=UTF-8&serverTimezone=Asia/Shanghai";
    String userName = "root";
    String pwd = "12345678";
    try {
        Class.forName(driverName);
        Connection con= DriverManager.getConnection(url,userName,pwd);
        String sql = "select * from t_student where 1=1";
        if(a!=null && a!=""){
            sql+=" and stu_name='"+a+"'";
        }
        if(b!=null && b!=""){
            sql+=" and sex='"+b+"'";
        }
        Statement stament= con.createStatement();
        ResultSet rs= stament.executeQuery(sql);
%>
<table>
    <tr>
        <td>姓名</td>
        <td>性别</td>
    </tr>
<%
        while (rs.next()){
            String stuName=rs.getString("stu_name");
            String sex = rs.getString("sex");
%>
    <tr>
        <td><%=stuName%></td>
        <td><%=sex%></td>
    </tr>
<%
        }
%>
</table>
<%
        rs.close();
        con.close();
    } catch (ClassNotFoundException e) {
        e.printStackTrace();
    }catch (SQLException e) {
        e.printStackTrace();
    }


%>

</body>
</html>
